#!/bin/bash
#
# Implements a rudimentary shell for testing and debugging Pulley
#
# Author:   Dr. Mike Murphy (mmurphy2@coastal.edu)
# Revision: 20 November 2013
#
#   Copyright 2013 Coastal Carolina University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#


## p_cmd_developer_shell_help
##
## Echoes help information for the developer_shell command. Returns 0.
##
function p_cmd_developer_shell_help() {
	cat << EOF
Usage: pulley developer_shell

Places Pulley into developer mode, which loads the kernel and implements
a rudimentary interactive shell. In this shell, the developer can run any
Pulley function to check operations.
EOF
	return 0
}


## p_cmd_developer_shell_summary
##
## Echoes summary information for the developer_shell command. Returns 0.
##
function p_cmd_developer_shell_summary() {
	echo "Enters an interactive developer shell"
	return 0
}


## p_cmd_developer_shell
##
## Implements the developer_shell command, providing a simple interactive
## shell for checking Pulley internals. Returns the exit status of the last
## command (other than "exit").
##
function p_cmd_developer_shell() {
	local status=0
	local cmd=
	local wd=$(pwd)
	
	echo -n "pulley> "
	while read -e cmd; do
		if [[ "${cmd}" == "exit" ]]; then
			break
		else
			eval ${cmd}
			status=$?
		fi
		
		echo -n "pulley> "
	done
	
	return ${status}
}
